package com.zsk.shop.controller.app;

import com.zsk.shop.common.annotion.NoPermission;
import com.zsk.shop.common.base.BaseResponse;
import com.zsk.shop.common.utils.ToolUtil;
import com.zsk.shop.model.params.CategoryGoodsParams;
import com.zsk.shop.model.params.GoodsCategoryParams;
import com.zsk.shop.model.params.HomeGoodsByLabelParams;
import com.zsk.shop.model.results.HomeGoodsLabelList;
import com.zsk.shop.model.results.HomeGoodsResult;
import com.zsk.shop.model.results.ShopGoodsCategoryTreeResult;
import com.zsk.shop.model.results.ShopGoodsDetailResult;
import com.zsk.shop.service.ShopGoodsCategoryService;
import com.zsk.shop.service.ShopGoodsLabelService;
import com.zsk.shop.service.ShopGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ljh
 * @create 2021/11/17 17:01
 */
@RestController
@Api(tags = "商城-商品相关")
@RequestMapping("/shop/goods")
public class ShopGoodsController {

    @Resource
    private ShopGoodsService shopGoodsService;
    @Resource
    private ShopGoodsLabelService shopGoodsLabelService;
    @Resource
    private ShopGoodsCategoryService shopGoodsCategoryService;

    @NoPermission
    @ApiOperation(value = "商品【详情】")
    @GetMapping("/goodsDetailByNo.do")
    @ApiImplicitParams({@ApiImplicitParam(name = "goodsNo", value = "商品no"),
            @ApiImplicitParam(name = "goodsOrderType", value = "1 普通，2 0元购，3 会员商城, 4 特殊")})
    public BaseResponse<ShopGoodsDetailResult> goodsDetail(String goodsNo, Integer goodsOrderType) {
        if (ToolUtil.isEmpty(goodsNo)) {
            return BaseResponse.error("商品编号错误");
        }
        return shopGoodsService.goodsDetailByNo(goodsNo, goodsOrderType);
    }

    @NoPermission
    @ApiOperation(value = "【首页-类目列表（8个+）】所有商品一级类目")
    @PostMapping("/goodsCategoryFirstList.do")
    public BaseResponse<List<GoodsCategoryParams>> goodsCategoryFirstList() {
        return shopGoodsCategoryService.goodsCategoryFirstList();
    }

    @NoPermission
    @ApiOperation(value = "分类下的商品")
    @PostMapping("/getCategoryFirstGoodsList.do")
    public BaseResponse<List<HomeGoodsResult>> getCategoryFirstGoodsList(@RequestBody CategoryGoodsParams params) {
        return shopGoodsService.getCategoryFirstGoodsList(params);
    }

    @NoPermission
    @ApiOperation(value = "【首页】所有商品标签及其最多4个商品")
    @PostMapping("/goodsLabelList.do")
    public BaseResponse<List<HomeGoodsLabelList>> goodsLabelList() {
        return shopGoodsLabelService.goodsLabelList();
    }

    @NoPermission
    @ApiOperation(value = "【首页：标签查看更多】标签下所有商品分页")
    @PostMapping("/goodsByLabelList.do")
    public BaseResponse<List<HomeGoodsResult>> goodsByLabelList(@RequestBody HomeGoodsByLabelParams params) {
        return shopGoodsService.goodsByLabelList(params);
    }

    @NoPermission
    @ApiOperation(value = "【分类首页】所有商品类目层级")
    @PostMapping("/goodsCategoryTreeList.do")
    public BaseResponse<List<ShopGoodsCategoryTreeResult>> goodsCategoryTreeList() {
        return shopGoodsCategoryService.goodsCategoryList(false);
    }

    @NoPermission
    @ApiOperation(value = "【首页:0元购 / 会员商品 更多页】所有分页-0元购商品/会员商品")
    @GetMapping("/goodsItemList.do")
    @ApiImplicitParams({@ApiImplicitParam(name = "type", value = "'zero':代表0元购 | 'vip':代表会员", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "分页第几页", dataType = "String"),
            @ApiImplicitParam(name = "limit", value = "分页每页多少条", dataType = "String")})
    public BaseResponse<HomeGoodsResult> goodsItemList(String type, String page, String limit) {
        return shopGoodsService.goodsItemList(type, page, limit);
    }

    @NoPermission
    @ApiOperation(value = "【拆除列表：点击购买】复购商品列表")
    @GetMapping("/againGoodsByGoodsVipLevel.do")
    public BaseResponse<List<HomeGoodsResult>> againGoodsByGoodsVipLevel(Integer goodsVipLevel, String page, String limit) {
        return shopGoodsService.againGoodsByGoodsVipLevel(goodsVipLevel, page, limit);
    }

}
